Partial Class Forgot
  Inherits System.Web.UI.Page

  Protected Sub Cancel_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cancel_btn.Click
    Response.Redirect("~/SignIn.aspx")
  End Sub

  Protected Sub OK_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OK_btn.Click
    If Trim(Username_txt.Text) = "" Then Exit Sub

    Try
      Dim dm As New DAOMain.CommonDAO
      Dim sConn As New Data.SqlClient.SqlConnection
      Dim sCom As New Data.SqlClient.SqlCommand
      Dim sDApt As New Data.SqlClient.SqlDataAdapter(sCom)
      Dim sDT As New Data.DataTable

      sCom.CommandText = "SELECT email_address, user_password FROM [USER_MSTR] where user_name=" & _
        dm.Q(Trim(Username_txt.Text))

      sConn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("CnnStr")
      sCom.CommandType = Data.CommandType.Text
      sCom.Connection = sConn
      sConn.Open()
      sDApt.Fill(sDT)

            If sDT.Rows.Count = 1 Then
                Dim objConfig As Object
                objConfig = CreateObject("CDO.Configuration")

                With objConfig.Fields
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "202.81.162.37"
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
                    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "cims@rtamsi.com"
                    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "janispagal"
                    .Update()
                End With

                Dim objMessage As Object
                objMessage = CreateObject("CDO.Message")
                objMessage.Configuration = objConfig
                objMessage.Subject = "CIMS generated email"
                objMessage.From = """CIMS Administrator"" <CIMSadmin@cims.com>"
                objMessage.To = Trim(sDT.Rows(0).Item(0).ToString)
                objMessage.TextBody = "Your password is """ & Trim(sDT.Rows(0).Item(1)) & """." & vbCrLf & _
                  "Do not reply to this email."
                objMessage.Send()

                Dim jr As New PolyFunc.ASPFunc
                jr.MessageAlert(Me, "Email successfully sent.")
            End If

    Catch ex As Exception

    End Try

  End Sub
End Class